package work.chenxr.ds.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import work.chenxr.ds.entity.DsEntity;
import work.chenxr.ds.mapper.DsMapper;
import work.chenxr.ds.service.DsService;

import java.util.List;

/**
 * @Author Chenxr
 * @Date 2023/10/23
 * @Description
 */
@Service
@AllArgsConstructor
public class DsServiceImpl implements DsService {
    private final DsMapper dsMapper;

    @Override
    @DS("master_1")
    public boolean insertDsMaster_1() {
        DsEntity dsEntity = new DsEntity();
        dsEntity.setContent("dsMaster_1");
        return dsMapper.insertSelective(dsEntity) > 0;
    }

    @Override
    @DS("master_2")
    public boolean insertDsMaster_2() {
        DsEntity dsEntity = new DsEntity();
        dsEntity.setContent("dsMaster_2");
        return dsMapper.insertSelective(dsEntity) > 0;
    }

    @Override
    @DS("slave_1")
    public boolean insertDsSlave_1() {
        DsEntity dsEntity = new DsEntity();
        dsEntity.setContent("dsSlave_1");
        return dsMapper.insertSelective(dsEntity) > 0;
    }

    @Override
    @DS("slave_2")
    public boolean insertDsSlave_2() {
        DsEntity dsEntity = new DsEntity();
        dsEntity.setContent("dsSlave_2");
        return dsMapper.insertSelective(dsEntity) > 0;
    }

    @Override
    @DS("master_1")
    public List<DsEntity> listDsMaster_1() {
        return dsMapper.selectAll();
    }

    @Override
    @DS("master_2")
    public List<DsEntity> listDsMaster_2() {
        return dsMapper.selectAll();
    }

    @Override
    @DS("slave_1")
    public List<DsEntity> listDsSlave_1() {
        return dsMapper.selectAll();
    }

    @Override
    @DS("slave_2")
    public List<DsEntity> listDsSlave_2() {
        return dsMapper.selectAll();
    }
}
